package com.jadows.tdog.domain;

import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Sharded;
import org.springframework.data.mongodb.core.mapping.ShardingStrategy;

import java.io.Serializable;
import java.util.Date;

/**
 * 聊天记录
 *
 * @author taojiacheng
 */
@Data
@Document(collection = "chat_messages")
@Accessors(chain = true)
@Sharded(shardKey = "unionId", shardingStrategy = ShardingStrategy.HASH)
public class ChatMessage implements Serializable {

    @Id
    private Long messageId;
    private String fromUid;

    @Indexed
    private Date sendTime;

    private String toUid;

    /**
     * unionId
     * fromUid 和 toUid 的组合
     */
    @Indexed
    private String unionId;

    private String content;

    private Long roomId;

    /**
     * 消息类型
     */
    private String action;

    /**
     * 0 正常 2 撤回 3 焚毁 ...
     * 消息状态
     */
    private Byte status = 0;

    /**
     * 是否已读
     */
    private Boolean isRead = false;

}
